package com.haiyou.dc.thread.test4;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo4 implements Callable<Integer> {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Demo4 demo4 = new Demo4();

        FutureTask<Integer> futureTask = new FutureTask<>(demo4);
        Thread thread = new Thread(futureTask);
        thread.start();

        System.out.println("----------->");

        Integer result = futureTask.get();
        System.out.println("执行结果=" + result);

        Integer result2 = futureTask.get();
        System.out.println("执行结果2=" + result2);
    }

    @Override
    public Integer call() throws Exception {
        System.out.println("正在计算....");
        Thread.sleep(3000);
        return 1;
    }
}
